package cn.sinohealth.util;


import cn.sinohealth.model.EsConstantModel;
import freemarker.cache.ClassTemplateLoader;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;

import java.io.IOException;
import java.io.StringWriter;

/**
 * @author qinminghui
 * @description TODO
 * @date 2020/9/18
 */
public class TemplateUtils {
    public static final Configuration configuration = new Configuration(Configuration.getVersion());

    static {
        configuration.setTemplateLoader(new ClassTemplateLoader(TemplateUtils.class.getClassLoader(), "template"));
    }

    public static String writeEsConstant(EsConstantModel esConstantModel) throws IOException, TemplateException {
        final Template template = configuration.getTemplate("esConstant.ftl");
        final StringWriter writer = new StringWriter();
        template.process(esConstantModel, writer);
        writer.flush();
        return writer.toString();
    }
}
